<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户信息修改</title>
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/font-awesome/css/font-awesome.css}" rel="stylesheet">
    <link th:href="@{/css/plugins/iCheck/custom.css}" rel="stylesheet">
    <link th:href="@{/css/animate.css}" rel="stylesheet">
    <link th:href="@{/css/style.css}" rel="stylesheet">
    <link th:href="@{/css/custom.css}" rel="stylesheet">
</head>
<body class="gray-bg">

<div class="middle-box text-center loginscreen   animated fadeInDown">
    <div>
        <div>
            <h1 class="logo-name"></h1>
        </div>
        <h3>修改用户信息</h3>
        <form id="form-user" class="m-t" role="form" action="registerUser" method="post">
            <div class="form-group">
                <select id="usertype" class="form-control">
                    <option value="0">请选择用户类型</option>
                    <option value="0">普通用户</option>
                    <option value="1">渠道商</option>
                    <option value="2">渠道专员</option>
                    <option value="3">系统管理员</option>
                </select>
            </div>
            <div class="form-group">
                <select id="userlevel" class="form-control">
                    <option value="0">请选择用户等级</option>
                    <option value="0">普通用户</option>
                    <option value="1">vip用户</option>
                    <option value="2">vvip用户</option>
                </select>
            </div>
           <!-- <div class="form-group">
                <input autocomplete="off" type="text" id="telephone" name="telephone"
                       onKeyUp="value=value.replace(/[\W]/g,'')" class="form-control" placeholder="请输入手机号码" required>
            </div>-->
            <div class="form-group">
                <input autocomplete="off" type="text" id="username" name="username" class="form-control"
                       placeholder="请输入姓名" required>
            </div>

            <!--<div class="form-group">
                <input autocomplete="off" type="password" id="password" name="password" class="form-control"
                       placeholder="请输入密码" required>
            </div>-->
            <!--<div class="form-group">
                <input autocomplete="off" type="text" id="institution" name="institution" class="form-control"
                       placeholder="请输入机构全称" required>
            </div>-->

            <div class="form-group">
                <select id="institution" class="form-control">
                    <option value="0">请选择机构全称</option>

                </select>
            </div>

           <!-- <div class="form-group">
                <input autocomplete="off" type="text" id="institution_short" name="institution_short"
                       class="form-control" placeholder="请输入机构简称" required>
            </div>-->
            <div class="form-group">
                <input autocomplete="off" type="number" id="term_of_validity" name="term_of_validity" class="form-control"
                       placeholder="请输入有效期单位（天）"  required>
            </div>
            <!--<div class="form-group">
                <input autocomplete="off" type="text" id="system_title" name="system_title" class="form-control"
                       placeholder="请输入系统名称" required>
            </div>-->
            <button type="button" onclick="update()" class="btn btn-primary block full-width m-b">提交</button>
            <a href="list" type="button" class="btn btn-white block full-width m-b">取消</a>
        </form>
    </div>
</div>

<!-- Mainly scripts -->
<script th:src="@{/js/jquery-2.1.1.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
<script th:src="@{/js/slef/updateUser.js}"></script>
<script th:inline="javascript" type="text/javascript">
    var ctxPath = /*[[@{/}]]*/'';
    $("#currentyear").text((new Date()).getFullYear());

        var data = [[${data}]];

        var dataUser = data.user;

        var dataOrganization = data.organization;

        var oldTime;

        //所有公司名数据组装
    for (let i = 0; i < dataOrganization.length; i++){
        let organization = dataOrganization[i];
        $("#institution").append(" <option value=\""+organization.organization_id+"\">"+organization.organization_name+"</option>")

        if (dataUser.organization_id == organization.organization_id){
            $("#institution option:eq("+(i+1)+")").attr("selected" , 'selected');

            computationTime(organization.term_of_validity);
        }
    }

    //选择机构点击事件
    $("#institution").on("change" , function () {

        let oid = $("#institution option:selected").val();
        for (let i = 0; i < dataOrganization.length; i++){
            let organization = dataOrganization[i];
            if (oid == organization.organization_id){
                computationTime(organization.term_of_validity);
            }
        }
    })




    //时间计算 ，用户有效期

    function computationTime(endDate){

        endDate =endDate.substring(0 , 10);

        oldTime = endDate;

        endDate = Date.parse(endDate);

        var nowDate= data.nowDate;
        nowDate = Date.parse(nowDate);

        let days = 0;

        if (endDate > nowDate){
            days = (endDate - nowDate)/(1*24*60*60*1000);
        }

        //有效时间
        $("#term_of_validity").val(days);
    }





        //用户类型
        $("#usertype option").each(function () {



            if($(this).text() != '请选择用户类型' && $(this).val() == dataUser.user_type){

                $(this).attr("selected" , 'selected');

            }
        })


    //用户等级
    $("#userlevel option").each(function () {



        if($(this).text() != '请选择用户类型' && $(this).val() == dataUser.user_level){

            $(this).attr("selected" , 'selected');

        }
    })

    //用户姓名
        $("#username").val(dataUser.username);
























</script>
<div class="page-footer">
    © 2014-<span id="currentyear"></span> 南京涌亿思信息技术有限公司 苏ICP备17066984号-1
</div>
</body>

</html>
